package com.cr.mrapp.Controller;

import com.cr.mrapp.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @RequestMapping("/orderList.html")
    public String toOrderList() { return "orderList"; }

    @RequestMapping("/delete.do")
    @ResponseBody
    public Object deleteById(int id){
        Map<String,Object> responseData = new HashMap<>();
        int row = orderService.deleteById(id);
        if(row>0){
            responseData.put("code", 200);
            responseData.put("msg","删除成功");
            responseData.put("data",row);
        }else {
            responseData.put("code", 500);
            responseData.put("msg","删除失败");
            responseData.put("data",0);
        }
        return responseData;
    }
    @RequestMapping("/orderList.do")
    @ResponseBody
    public Object findByPage(int page, int limit){

        List<Object> list = orderService.findByPage(page, limit);
        int count = orderService.findCount();

        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","查询成功");
        map.put("count",count);
        map.put("data",list);
        return map;
    }
}
